import urlConfig from './config.js'
module.exports = (params) =>{
	let url = urlConfig+params.url;
	let method = params.method;
	let header = params.header || {};
	let data = params.data || {};
	let loaddings = params.hideLoading||true;
	if(method){
		method = method.toUpperCase();
		if(method == "POST"){
			// header = {"content-type":"application/x-www-form-urlencoded"}
			header = {"content-type":"application/json"}
		}
	}
	// if(!params.hideLoading){
	// 	uni.showLoading({
	// 		title:"加载中..."
	// 	})
	// }
	//网络请求
	uni.request({
		url:url,
		method:method || "GET",
		header:header,
		data:data,
		dataType:"json",
		sslVerify:false,
		timeout: 300000,
		success:res=> {
			if(res.statusCode && res.statusCode != 200){
				uni.showModal({
					content:res.msg
				});
				return;
			}
			typeof params.success == "function" && params.success(res.data);
		},
		fail: err => {
			// uni.showModal({
			// 	content:err.msg
			// })
			typeof params.fail == "function" && params.fail(err.data);
		},
		complete: (e) => {
			uni.hideLoading();
			typeof params.complete == "function" && params.complete(e.data);
			return;
		}
	})
}